package cn.tedu.order.service;

import cn.tedu.order.mapper.OrderMapper;
import com.jt.common.pojo.Order;
import com.jt.common.pojo.OrderItem;
import com.jt.common.utils.UUIDUtil;
import com.jt.common.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;

@Service
public class OrderService {
    @Autowired
    OrderMapper orderMapper;

    public List<Order> queryMyOrders(String userId) {
        List<Order> oList = orderMapper.selectOrderByUserId(userId);
        return oList;
    }

    /**
     * 提交订单，新增入库
     * @param order
     */
    public void addOrder(Order order) {
        // 缺少orderId
        order.setOrderId(UUIDUtil.getUUID());
        // order对象中的orderItems元素对象orderItem也需要orderId属性值
        order.setOrderPaystate(0);
        order.setOrderTime(new Date());
        orderMapper.insertOrder(order);
    }

    /**
     * 删除订单
     * @param orderId
     */
    public void deleteOrder(String orderId) {
        orderMapper.deleteOrderByOrderId(orderId);
    }
}
